//
//  DHChangePwdController.m
//  精品酒店
//
//  Created by DIANGHONG on 2018/5/16.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "DHChangePwdController.h"

@interface DHChangePwdController ()
@property (weak, nonatomic) IBOutlet UIButton *btnCommitPwd;
@property (weak, nonatomic) IBOutlet UITextField *oldPwdTxtField;
@property (weak, nonatomic) IBOutlet UITextField *pwdNewTxt;
@property (weak, nonatomic) IBOutlet UITextField *pwdConfirmTxt;



@end

@implementation DHChangePwdController
- (IBAction)commitButtonClick:(UIButton *)sender
{
    if (!self.oldPwdTxtField.hasText) {[SVProgressHUD showInfoWithStatus:@"请输入旧密码"];return;}
    if (!self.pwdNewTxt.hasText) {[SVProgressHUD showInfoWithStatus:@"请输入新的密码"];return;}
    if (!self.pwdConfirmTxt.hasText) {[SVProgressHUD showInfoWithStatus:@"请输入再次输入新的密码"];return;}
    
    if (![self.pwdNewTxt.text isEqualToString:self.pwdConfirmTxt.text])
    {[SVProgressHUD showInfoWithStatus:@"新密码不一致, 请重新输入"];return;}
    
    NSString *url = [NSString stringWithFormat:@"%@%@",REMOTEURL,@"index.php?act=member_index&op=change_pwd"];
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"key"] = DHNetworkManager.shareManager.userAccount.key;
    dictM[@"old_password"] = self.oldPwdTxtField.text;
    dictM[@"new_password"] = self.pwdConfirmTxt.text;
    
    [DHNetworkManager.shareManager requestWithMethod:MethodPost
                                           UrlString:url
                                              params:dictM.copy
                                          completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            [SVProgressHUD showErrorWithStatus:@"请检查网络"];
            return ;
        }
        // 失败
        if (json[@"error"]) {
            [SVProgressHUD showInfoWithStatus:json[@"error"]];
            return;
        }
        // 修改成功
        if ([json[@"datas"] boolValue]) {
            [SVProgressHUD showSuccessWithStatus:@"修改成功"];
            //[self.navigationController popToRootViewControllerAnimated:true]
           // [self.navigationController popToRootViewControllerAnimated:true];
            [self.navigationController popToViewController:self.navigationController.childViewControllers[1] animated:true];
        
        }
       
    }];


}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.btnCommitPwd.layer.masksToBounds = true;
    self.btnCommitPwd.layer.cornerRadius = 8;
    
}


@end
